import { _decorator, Component, Node, Animation } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('box')
export class box extends Component {
    @property({ type: Node })
    private anim: Node = null;

    start() {
        // 获取动画组件
        const animation = this.anim.getComponent(Animation);
        if (animation) {
            // 播放名为 test 的动画
            animation.play('test');
            console.log("111")
        } else {
            console.error('No Animation component found on anim node!');
        }
    }

    // 提供一个公共方法来手动触发动画
    public playAnimation() {
        const animation = this.anim.getComponent(Animation);
        if (animation) {
            animation.play('test');
        }
    }
}
